﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RIS.TMP.WEB.APP.Models;
using RIS.TMP.WEB.APP.AddMigrations;

namespace RIS.TMP.WEB.APP.Controllers
{
    public class CFGroupPMController : Controller
    {
        private AllContext db = new AllContext();

        //
        // GET: /CFGroupPM/

        public ActionResult Index()
        {
            return View(db.CFGroupPMs.Where(x => x.RecordStatus == "U").ToList());
        }

        //
        // GET: /CFGroupPM/Details/5

        public ActionResult Details(int id = 0)
        {
            CFGroupPM cfgrouppm = db.CFGroupPMs.Find(id);
            if (cfgrouppm == null)
            {
                return HttpNotFound();
            }
            return View(cfgrouppm);
        }

        //
        // GET: /CFGroupPM/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /CFGroupPM/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(CFGroupPM cfgrouppm)
        {
            if (ModelState.IsValid)
            {
                cfgrouppm.RecordStatus = "U";
                cfgrouppm.CreateBy = Session["LogedId"].ToString();
                cfgrouppm.CreateWhen = DateTime.Now;
                db.CFGroupPMs.Add(cfgrouppm);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(cfgrouppm);
        }

        //
        // GET: /CFGroupPM/Edit/5

        public ActionResult Edit(int id = 0)
        {
            CFGroupPM cfgrouppm = db.CFGroupPMs.Find(id);
            if (cfgrouppm == null)
            {
                return HttpNotFound();
            }
            return View(cfgrouppm);
        }

        //
        // POST: /CFGroupPM/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(CFGroupPM cfgrouppm)
        {
            if (ModelState.IsValid)
            {
                db.Entry(cfgrouppm).State = EntityState.Modified;
                cfgrouppm.UpdateBy = Session["LogedId"].ToString();
                cfgrouppm.UpdateWhen = DateTime.Now;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(cfgrouppm);
        }

        //
        // GET: /CFGroupPM/Delete/5

        public ActionResult Delete(int id = 0)
        {
            CFGroupPM cfgrouppm = db.CFGroupPMs.Find(id);
            if (cfgrouppm == null)
            {
                return HttpNotFound();
            }
            return View(cfgrouppm);
        }

        //
        // POST: /CFGroupPM/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            CFGroupPM cfgrouppm = db.CFGroupPMs.Find(id);
            db.Entry(cfgrouppm).State = EntityState.Modified;
            cfgrouppm.RecordStatus = "D";
            cfgrouppm.UpdateBy = Session["LogedId"].ToString();
            cfgrouppm.UpdateWhen = DateTime.Now;
            //db.CFGroupPMs.Remove(cfgrouppm);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}